const { saveCommunityService, getCommunityService, getCommunityAttentionService,
    saveCommunityAttentionService, saveComConversationService, getComConversationService,getCommunityUserNumService } = require('../service/community.servcie')
class communityController {
    async saveCommunity(ctx, next) {
        const { community_name, community_detail, creator, user_id, is_delete = 0 } = ctx.request.body
        try {
            const res = await saveCommunityService({ community_name, community_detail, creator, user_id, is_delete })
            ctx.body = {
                code: 1000,
                res
            }
        } catch (err) {

        }
    }
    async getCommunity(ctx, next) {
        const { community_name, community_detail, creator, user_id, is_delete = 0, currentPage = 1, pageSize = 10 } = ctx.request.query
        try {
            const { data } = await getCommunityService({ community_name, community_detail, creator, user_id, is_delete, pageSize, currentPage })
            ctx.body = {
                code: 1000,
                data,
                current: currentPage,
                pageSize: pageSize
            }
        } catch (err) {

        }
    }
    async getCommunityAttention(ctx, next) {
        const { user_id } = ctx.request.query
        try {
            const { data } = await getCommunityAttentionService({ user_id })
            ctx.body = {
                code: 1000,
                data,

            }
        } catch (err) {

        }
    }

    async saveCommunityAttention(ctx, next) {
        const { user_id, username, community_name, community_id } = ctx.request.body
        console.log(11111111111,user_id, username, community_name, community_id)
        try {
            const res = await saveCommunityAttentionService({ user_id, username, community_name, community_id })
            ctx.body = {
                code: 1000,
                res,

            }
        } catch (err) {

        }
    }

    async getComConversation(ctx, next) {
        const { community_id='' } = ctx.request.query
        try {
            const { data } = await getComConversationService({ community_id })
            ctx.body = {
                code: 1000,
                data,

            }
        } catch (err) {

        }
    }
    async saveComConversation(ctx, next) {
        const { user_id, username, avator='', community_id='', content='' } = ctx.request.body
        try {
            const res = await saveComConversationService({ user_id, username, avator, community_id, content })
            ctx.body = {
                code: 1000,
                res,

            }
        } catch (err) {

        }
    }
    async getCommunityUserNum(ctx, next) {
        try {
            const res = await getCommunityUserNumService()
            ctx.body = {
                code: 1000,
                res,

            }
        } catch (err) {

        }
    }
}
// 导出实例化的对象
module.exports = new communityController()